import http from 'node:http';
import https from 'node:https';
import {readFileSync} from 'node:fs';

function createServer(keyFile, certFile) {
  let server, key, cert;

  if (keyFile && certFile) {
    key = readFileSync(keyFile);
    cert = readFileSync(certFile);
  }

  if (key && cert) {
    server = https.createServer({key, cert});
  } else {
    server = http.createServer();
  }

  return server;
}

export default createServer;
